<?php
/**
 -----------------------------
 *  功能:登录模型文件
 */
namespace Home\Model;
use Think\Model;
class LoginModel extends Model{
	public function auth(){
		$datas = $_POST;
		$M = M("admin");
		if ($M->where(array('username'=>$datas['username']))->count() >= 1) {
			$userinfo = $M->where(array('username'=>$datas['username']))->find();
			if($userinfo){
			    if($userinfo["password"] != md5($datas['password'])){
			        return array('status' => 1, 'info' => "用户名或密码错误1");
			    }
			    if ($userinfo['status'] == 0) {
			        return array('status' => 1, 'info' => "你的账号被禁用，有疑问联系管理员吧");
			    }  
        		$roleid=$userinfo["roleid"];
        		$info = $M->where(array('username'=>$datas['username']))->join('md_rolepower ON md_admin.roleid = md_rolepower.roleid')->find();
        		if($info){
        		    $_SESSION['my_info'] = $info;//将信息储存到SESSION中        		    
        		    return array('status' => 0, 'info' => "登录成功");
        		}else{
        		    return array('status' => 1, 'info' => "用户名或密码错误2");
        		}
        	   /**		
        			if(M('power')->where(array('uid'=>$info['uid']))->find()){
        				$info = $M->where(array('username'=>$datas['username']))->join('md_power ON md_admin.uid = md_power.uid')->find();
        			}

    			if ($info['status'] == 0) {
    				return array('status' => 1, 'info' => "你的账号被禁用，有疑问联系管理员吧");
    			}
    			if ($info['password'] == md5($datas['password'])) {
    				$_SESSION['my_info'] = $info;//将信息储存到SESSION中
    				return array('status' => 0, 'info' => "登录成功");
    			}else{
    				return array('status' => 2, 'info' => "用户名或密码错误");
    			}
    			**/
			}
		}else{
			return array('status' => 3, 'info' => "用户名已经存在多个账号，请联系管理员");
		}
	}
}